package com.zxgj.datadirect.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxgj.datadirect.entity.DataDirectCatalog;
import com.zxgj.datadirect.service.DataDirectCatalogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 数据目录控制器
 */
@Api(tags = "数据目录管理")
@RestController
@RequestMapping("/data/catalog")
public class DataDirectCatalogController {

    @Autowired
    private DataDirectCatalogService dataDirectCatalogService;

    @ApiOperation("检查目录编码是否存在")
    @GetMapping("/exists/{catalogCode}")
    public boolean existsByCatalogCode(@PathVariable String catalogCode) {
        return dataDirectCatalogService.existsByCatalogCode(catalogCode);
    }

    @ApiOperation("按目录编码更新数据")
    @PutMapping("/update")
    public int updateByCatalogCode(@RequestBody DataDirectCatalog catalog) {
        return dataDirectCatalogService.updateByCatalogCode(catalog);
    }

    @ApiOperation("分页查询数据目录")
    @GetMapping("/page")
    public Page<DataDirectCatalog> selectCatalogPage(
            @RequestParam(defaultValue = "1") int current,
            @RequestParam(defaultValue = "10") int size,
            @RequestParam(required = false) String orgCode,
            @RequestParam(required = false) Integer dataType) {
        
        Page<DataDirectCatalog> page = new Page<>(current, size);
        return dataDirectCatalogService.selectCatalogPage(page, orgCode, dataType);
    }
}
